<template>
  <div id="home">
    <div style="padding: 20px 0;" v-html="speech"></div>
    <div class="amap-wrapper">
      <el-amap
          class="amap-box"
          :amap-manager="amapManager"
          :vid="'amap-vue'"
          :events="mapEvents"
      >
      </el-amap>
    </div>
  </div>
</template>
<script>
import tools from '../utils/tools'

const amapManager = new window.VueAMap.AMapManager();

export default {
  name: 'Home',
  data() {
    const that = this
    return {
      speech:"",
      useTime: "",
      distance: "",
      amapManager,
      mapEvents: {
        complete() {
          that.getDriving()
        },
        click(e) {
          const {lng, lat} = e.lnglat
          console.log(`你点击点的经纬度为：${lng},${lat}`)
        }
      }
    };
  },
  methods: {
    getDriving() {
      const map = this.amapManager.getMap()
      const driving = new AMap.Driving({
        map
      })
      const path = [{keyword: "双流国际机场"}, {keyword: "成都南站"}]
      driving.search(path, (status, result) => {
        console.log(status, "---", result)
        const useTime = tools.formatSeconds(result.routes[0].time)
        const distance = (result.routes[0].distance / 1000).toFixed(1) + '公里'
        this.speech = `
         <b><i class="el-icon-headset"> 语音播报：</i></b>
        <span>准备出发，全程${distance}，需要${useTime}。</span>
        `
      })
    }
  }
};
</script>
<style>
* {
  margin: 0;
  padding: 0;
}

#home {
  height: 70vh;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

.amap-wrapper {
  height: 100%;
}

.searchHeader {
  padding: 20px;
}
</style>
